import numpy as np

with open ('INDEX_20210127.txt')as f:
    data = f.readlines()
# print(data)  # ['ZCTH,20210127,90,90,80,80,0\n', 'ZCTW,20210127,20,20,10,10,0\n', ...]
    # !!! Request：[['ZCTH,20210127,90,90,80,80,0'], ['ZCTW,20210127,20,20,10,10,0\n'], ...] 
    data_str = ''
    # print('ZCTH,20210127,90,90,80,80,0\n' + 'ZCTW,20210127,20,20,10,10,0\n')
    # ZCTH,20210127,90,90,80,80,0
    # ZCTW,20210127,20,20,10,10,0
    for i in data:
        data_str = data_str + i
    # data_str.split(',')
    # print(data_str)
    # ZBTW,20210127,20,20,10,10,0
    # ZCFD,20210127,10,20,0.01,10,0
    # ZCFI,20210127,30,50,30,30,0
    data_01 = data_str.split('\n')
    # print(data_01)  
    # ['addrA,20210127,-152,-102,-165,-143,0', 'addrC,20210127,-75,-75,-242,-220,0']
    # list_01 = ['a', 'b', 'c', 'd']
    # list_02 = np.array(list01).reshape(4,1)
    data_03 = np.array(data_01).reshape(len(data_01), 1)
    print(data_03)
    print(data_03[0])
    # print(data_03[0][3])
# 缺逗号','，很尴尬。
# [['ADDA,20210127,-152,-102,-165,-143,0']
#  ['ADDC,20210127,-75,-75,-242,-220,0']
#  ['ADDE,20210127,-1067,-1067,-1807,-1807,0']
#  ...
#  ['ZCTH,20210127,90,90,80,80,0']
#  ['ZCTW,20210127,20,20,10,10,0']
#  ['']]

a = [
    ['SSCM',20210127,13159.02,13159.02,12753.9,12812.68,0],
    ['SSDI',20210127,4.65,4.65,4.65,4.65,0],
    ['SSEW',20210127,378.85,380.42,374.51,377.08,0],
    ['SVTR',20210127,186.42,186.44,178.59,180.4,0],
    ['TTMT',20210127,310.64,310.79,301.98,302.59,65161700]
]
print(f'这是a，{a}')
print(a)
print(a[0][3])
# [['SSCM', 20210127, 13159.02, 13159.02, 12753.9, 12812.68, 0], 
# ['SSDI', 20210127, 4.65, 4.65, 4.65, 4.65, 0]]

# [['ADDA,20210127,-152,-102,-165,-143,0']
# ['ADDC,20210127,-75,-75,-242,-220,0']
# ['']]

# for循环
# dict_01 = {}
# for x in data_03:
#     print(dict_01[ x[0] ])
#     print(x[3])
#     dict_01[ x[0] ] = x[3]
# print(dict_01)

# # 字典表达式
# dict_02 = {x[0]:x[3] for x in data_03}
# print(dict_02)

names = ['张三', '李四', '王五', '赵六', '李四', '张三', '赵六', '赵六', '王五', '赵六', '刘德华']
# names.count('张三')

# for循环
dict_03 = {}
for k in names:
    dict_03[k] = names.count(k)
print(dict_03)

# 字典生成式
dict_04 = {k:names.count(k) for k in names}
# 加个条件:
dict_05 = {k:names.count(k) for k in names if names.count(k) > 1}
print(dict_05)

# 两个一维列表生成字典
addr_En_01 = ['CHA', "ENG", 'GER']
addr_En_02 = [['CHA'], ["ENG"], ['GER']]
print(f'{addr_En_01[1], addr_En_02[1]}')  # 取出来一个是字符串，一个仍然是列表
addr_Cn = ['中国', '英国', '德国']
# list_CN_EN = zip(addr_Cn, addr_En)
# # for i in list_CN_EN:
# #     print(i)
dict_06 = {k[0]:k[1] for k in zip(addr_Cn, addr_En_01)}
print(dict_06)